package com.xyc.manager.global;

import com.xyc.manager.goods.bean.PageBean;
import com.xyc.manager.goods.service.GoodsService;
import com.xyc.manager.permission.bean.SysRole;
import com.xyc.manager.permission.service.PermissionService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("page")
public class PageController {
    @Resource
    private RestTemplate restTemplate;
    @Resource
    private PermissionService permissionService;
    @Resource
    private GoodsService goodsService;
    @RequestMapping("fun-tree.html")
    public String toPage(){
        return "fun-tree";
    }

    @RequestMapping("grant-permission.html")
    public String toGrantPermission(Model model){

           List<SysRole> sysRoles = permissionService.queryRoleList();
           model.addAttribute("list",sysRoles);

        return "grant-permission";
    }

    @RequestMapping("index.html")
    public String toIndex(){
        return "index";
    }

    @RequestMapping("login.html")
    public String toLogin(){
        return "login";
    }

    @RequestMapping("merchant-add.html")
    public String toMerchantAdd(){
        return "merchant-add";
    }

    @RequestMapping("goods-list.html")
    public String getGoodsList(Integer currentPage, Model model){
        //List<WxbGood> wxbGoods = goodsService.queryGoodsInfo(currentPage);
        if (currentPage == null){
            currentPage = 1;
        }
        //PageBean pageBean = goodsService.queryGoodsInfo(currentPage);
       // List<WxbGood> wxbGoods = pageBean.getWxbGoods();
        PageBean pageBean = restTemplate.getForObject("http://goods-server/goods/pageBeanBeiTai?currentPage=" + currentPage, PageBean.class);
        model.addAttribute("pageBean",pageBean);
        return "goods-list";
    }



}
